home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Sample Code / PartMaker 4.4 / PartMaker Documents / Script Runner• / Script Runner•.rsrc / dFRK_5031 < prev    next >
Encoding:
Text File  |  1995-12-12  |  5.2 KB  |  189 lines

  1. /*------------------------------------------------------------------------------
  2.     File:        ScriptRunnerAgent.cpp
  3.  
  4.     Contains:    The ScriptRunnerAgent SOM class implementation.
  5.  
  6.     Written by:    Sue Dumont
  7.     
  8.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  9. ------------------------------------------------------------------------------*/
  10.  
  11. // -- Compiler/Preprocessor Switches --
  12.  
  13. #ifndef _COMPILERDEFS_
  14. #include "CompDefs.h"
  15. #endif
  16.  
  17. // -- OpenDoc Utilities --
  18.  
  19. #ifndef _EXCEPT_
  20. // Exceptions define several important macros (eg. CHECKENV)
  21. // which are used in the SOM method dispatch glue. If Except.h
  22. // is not included early enough, exceptions may not be thrown
  23. // correctly when returning from a SOM method with the "ev" parameter set.
  24. #include <Except.h>
  25. #endif
  26.  
  27. // -- ScriptRunnerAgent Includes --
  28.  
  29. // Notification that this is a SOM source file
  30. #define Sample_ScriptRunnerAgent_Class_Source
  31.  
  32. // define underscore field names (ie. _fSelf)
  33. #define VARIABLE_MACROS
  34.  
  35. #ifndef SOM_Sample_ScriptRunnerAgent_xih
  36. #include "ScriptRunnerAgent.xih"
  37. #endif
  38.  
  39. // -- ScriptRunner includes --
  40.  
  41. #ifndef SOM_SampleCode_ScriptRunner_xh
  42. #include "ScriptRunner.xh"
  43. #endif
  44.  
  45. #ifndef SOM_Samples_PaletteExt_xh
  46. #include "PaletteExt.xh"
  47. #endif
  48.  
  49. // -- OpenDoc Includes --
  50.  
  51. #ifndef SOM_ODFrame_xh
  52. #include <Frame.xh>
  53. #endif
  54.  
  55. #ifndef SOM_ODSession_xh
  56. #include <ODSessn.xh>
  57. #endif
  58.  
  59. #ifndef SOM_ODWindow_xh
  60. #include <Window.xh>
  61. #endif
  62.  
  63. #ifndef SOM_ODWindowState_xh
  64. #include <WinStat.xh>
  65. #endif
  66.  
  67. // -- OpenDoc Utilities --
  68.  
  69. #ifndef _ODUTILS_
  70. #include <ODUtils.h>
  71. #endif
  72.  
  73. #ifndef _ODMEMORY_
  74. #include <ODMemory.h>
  75. #endif
  76.  
  77. #ifndef _ISOSTR_
  78. #include <ISOStr.h>
  79. #endif
  80.  
  81. #ifndef _TEMPOBJ_
  82. #include <TempObj.h>
  83. #endif
  84.  
  85. // -- Mac Includes --
  86.  
  87. #ifndef __ERRORS__
  88. #include <Errors.h>
  89. #endif
  90.  
  91. #pragma segment ScriptRunnerAgent
  92.  
  93. //==============================================================================
  94. // ScriptRunnerAgent
  95. //==============================================================================
  96.  
  97. //------------------------------------------------------------------------------
  98. // Method:        somInit
  99. //------------------------------------------------------------------------------
  100. SOM_Scope    void
  101. SOMLINK        ScriptRunnerAgent__somInit(Sample_ScriptRunnerAgent *somSelf)
  102. {
  103.     Sample_ScriptRunnerAgentData *somThis = Sample_ScriptRunnerAgentGetData(somSelf);
  104.    Sample_ScriptRunnerAgentMethodDebug("ScriptRunnerAgent","somInit");
  105.  
  106.     // somInit and somUninit methods behave like C++ constructors in that the
  107.     // inherited methods are called automatically.
  108.     // Thus, there is no need to call the parent class' somInit or somUninit.
  109.     
  110.     // There is also no need to set instance variables to zero/NULL
  111.     // since SOM guarantees that a newly constructed object is zeroed.
  112. }
  113.  
  114. //------------------------------------------------------------------------------
  115. // Method:        somUninit
  116. //------------------------------------------------------------------------------
  117. SOM_Scope    void
  118. SOMLINK        ScriptRunnerAgent__somUninit(Sample_ScriptRunnerAgent *somSelf)
  119. {
  120.     Sample_ScriptRunnerAgentData *somThis = Sample_ScriptRunnerAgentGetData(somSelf);
  121.     Sample_ScriptRunnerAgentMethodDebug("ScriptRunnerAgent", "somUninit");
  122. }
  123.  
  124. //------------------------------------------------------------------------------
  125. // Method:        AcquireScriptRunner
  126. // Origin:        ScriptRunnerAgent
  127. //
  128. // Description:    This method calls the draft to create the ScriptRunner
  129. //                part, and returns the palette extension as a result.
  130. //                The client part is responsible for releasing this
  131. //                extension.
  132. //------------------------------------------------------------------------------
  133. SOM_Scope    ODExtension*
  134. SOMLINK        ScriptRunnerAgent__AcquireScriptRunner
  135.             (
  136.                 Sample_ScriptRunnerAgent*        somSelf,
  137.                 Environment*                    ev,
  138.                 ODDraft*                        draft
  139.             )
  140. {
  141.     Sample_ScriptRunnerAgentData *somThis = Sample_ScriptRunnerAgentGetData(somSelf);
  142.     Sample_ScriptRunnerAgentMethodDebug("ScriptRunnerAgent", "AcquireScriptRunner");
  143.  
  144.     ODExtension* extension = kODNULL;
  145.  
  146.     SOM_TRY
  147.         // Get the draft's current permissions.
  148.         ODBoolean writeAccess = ( draft->GetPermissions(ev) >= kODDPSharedWrite );
  149.  
  150.         if ( writeAccess )
  151.         {
  152.             // If the ScriptRunner part exists, acquire it through the
  153.             // window ID. If not, call the draft's CreatePart method.
  154.             
  155.             if ( _fScriptRunnerID )
  156.             {
  157.                 // If the ScriptRunner ID is not null, make sure it's valid.
  158.                 TempODWindow window = ODGetSession(ev, draft)->GetWindowState(ev)
  159.                                         ->AcquireWindow(ev, _fScriptRunnerID);
  160.                 if ( window )
  161.                 {                
  162.                     TempODPart part = window->GetRootFrame(ev)->AcquirePart(ev);
  163.                     extension = part->AcquireExtension(ev, kPaletteExtension);
  164.                 }
  165.                 else
  166.                 {
  167.                     // Window not found. Set the ID back to null so the
  168.                     // ScriptRunner part can be created.
  169.                     _fScriptRunnerID = kODNULLID;
  170.                 }            
  171.             }                
  172.                                         
  173.             if ( _fScriptRunnerID == kODNULLID )
  174.             {
  175.                 // CreatePart will create the part and construct the real part by
  176.                 // calling its InitPart method. You can only call CreatePart if
  177.                 // the draft's permissions allow write access.
  178.                 TempODPart part = draft->CreatePart(ev, kScriptRunner, kODNoEditor);
  179.                 _fScriptRunnerID = part->Open(ev, kODNULL);
  180.                 extension = part->AcquireExtension(ev, kPaletteExtension);
  181.             }
  182.         }
  183.     
  184.     SOM_CATCH_ALL
  185.     SOM_ENDTRY
  186.     
  187.     return extension;
  188. }
  189.